package cjakma.study.portfolio.common.exception;

import org.springframework.context.MessageSourceResolvable;

import cjakma.study.portfolio.common.PortfolioResultCode;
import cjakma.study.portfolio.common.PortfolioResultMessage;

/**
 * 와글 예외 처리를 위한 클래스
 * 
 * @author 서성수
 * @see PortfolioResultCode
 * @see PortfolioResultMessage
 */
@SuppressWarnings("serial")
public class PortfolioException extends RuntimeException implements MessageSourceResolvable {
	
	private PortfolioResultMessage resultMessage;

	// Constructors

	/**
	 * 생성자
	 */
	public PortfolioException() {
		this(null, null);
	}

	/**
	 * 생성자
	 * 
	 * @param cause
	 *            the cause
	 */
	public PortfolioException(Throwable cause) {
		this(null, cause);
	}

	/**
	 * 생성자
	 * 
	 * @param resultMessage
	 *            {@link PortfolioResultMessage}
	 */
	public PortfolioException(PortfolioResultMessage resultMessage) {
		this(resultMessage, null);
	}

	/**
	 * 생성자
	 * 
	 * @param resultMessage
	 *            {@link PortfolioResultMessage}
	 * @param cause
	 *            the cause
	 */

	public PortfolioException(PortfolioResultMessage resultMessage, Throwable cause) {
		super(cause);
		if (resultMessage != null) {
			this.resultMessage = resultMessage;
		} else {
			this.resultMessage = PortfolioResultCode.UNKNOWN_ERROR.message();
		}
	}

	// Auto generate getters

	/**
	 * Get the {@link PortfolioResultCode}
	 */
	public PortfolioResultCode getResultCode() {
		return resultMessage.getResultCode();
	}

	/**
	 * Get the {@link PortfolioResultMessage}
	 */
	public PortfolioResultMessage getResultMessage() {
		return resultMessage;
	}

	// Throwable Override/Implement methods

	@Override
	public String getMessage() {
		return resultMessage.toString();
	}

	// MessageSourceResolvable Override/Implement methods

	//@Override
	public String[] getCodes() {
		return resultMessage.getCodes();
	}

	//@Override
	public Object[] getArguments() {
		return resultMessage.getArguments();
	}

	//@Override
	public String getDefaultMessage() {
		return resultMessage.getDefaultMessage();
	}
	
}